package com.qtyx.nms.ui.fragment

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.ldd.base.ui.fragment.BaseLddFragment
import com.qtyx.nms.R
import com.qtyx.nms.mvp.model.bean.MessageBean
import com.qtyx.nms.mvp.model.bean.NurseBean
import com.qtyx.nms.ui.activity.HomePageActivity
import com.qtyx.nms.ui.activity.MessageListActivity
import com.qtyx.nms.ui.activity.NurseBedListActivity
import com.qtyx.nms.ui.adapter.HomePageMessageAdapter
import com.qtyx.nms.ui.adapter.YiShiAdapter
import com.qtyx.nms.util.IntentKey
import kotlinx.android.synthetic.main.fg_message.*
import kotlinx.android.synthetic.main.fg_yishi.*
import java.util.ArrayList


/**
 * 医师列表
 */
class YiShiFragment : BaseLddFragment() {
    override fun getLayoutId() = R.layout.fg_yishi
    override fun initData() {
    }

    var adapter: YiShiAdapter?=null
    private var listYishi= mutableListOf<NurseBean.Data>()

    fun setData(list: List<NurseBean.Data>) {
        if (list.isNotEmpty()) {
            listYishi.clear()
            listYishi.addAll(list)
            rvHomepageYiShi.visibility = View.VISIBLE
            tvYiShiEmptyHint.visibility = View.GONE
            rvHomepageYiShi.layoutManager = LinearLayoutManager(mContext)
            if(null==adapter){
                adapter= YiShiAdapter(mContext, listYishi)
                rvHomepageYiShi.adapter = adapter
                //点击需要判断是否进入消息列表返回时候更新消息数据
                adapter?.onItemClickListener=object: YiShiAdapter.OnItemClickListener{
                    override fun onItemClick(position: Int, data: NurseBean.Data) {
                        val bundle=Bundle()
                        bundle.putSerializable(IntentKey.nurseBedInfo, data)
                        startActivityCustom(NurseBedListActivity::class.java,bundle)
                    }
                }
            }else{
                adapter?.notifyDataSetChanged()
            }

        } else {
            rvHomepageYiShi.visibility = View.GONE
            tvYiShiEmptyHint.visibility = View.VISIBLE
        }
    }

}